﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.Controllers;

namespace QLBH.Modules
{
    public partial class ucBillSale : UserControl
    {
        private BillSaleController controller;
        public ucBillSale()
        {
            InitializeComponent();
            controller =new BillSaleController(this);
            lbGood.Columns.Add("Mặt Hàng");
            lbGood.Visible = false;
        }

        private void ucBillSale_Load(object sender, EventArgs e)
        {
            controller.getdataWarehouse();
        }

        public void DisplayData(List<Models.WarehouseModel> data)
        {
            cbbWarehouse.DataSource = data;
            cbbWarehouse.DisplayMember = "name";
            cbbWarehouse.ValueMember = "id";
        }


        private void txtGoodName_TextChanged(object sender, EventArgs e)
        {
            if (txtGoodName.Text != "")
            {
                lbGood.Clear();
                controller.getdataGood(txtGoodName.Text);
                lbGood.Visible = true;
            }
            else
            {
                lbGood.Visible = false;
            }
        }


        public void DisplayDataGood(List<Models.GoodModel> data)
        {
            foreach (var item in data)
            {
                lbGood.Items.Add(item.Id.ToString(), item.Name, 0);
            }
        }
        private string idgood="";
        private void lbGood_SelectedIndexChanged(object sender, EventArgs e)
        {
            idgood = lbGood.SelectedItems[0].Name.ToString();
            MessageBox.Show(idgood);
            txtGoodName.Text = lbGood.SelectedItems[0].Text;
            lbGood.Visible = false;
            lbGood.Clear();
        }
    }
}
